<?php

class Application_Form_User extends My_Form
{
    public function init()
    {
        parent::init();

        $firstName = $this->createElement('text', 'firstName');
        $firstName->setLabel('Имя')
            ->setRequired(true)
            ->addFilter('StringTrim')
            ->addValidator('StringLength', false, array(1, 50));


        $lastName = $this->createElement('text',  'lastName');
        $lastName->setLabel('Фамилия')
            ->setRequired(false)
            ->addFilter('StringTrim')
            ->addValidator('StringLength', false, array(0, 50));

        $city = $this->createElement('select',  'city');
        $city->setLabel('Город')
            ->setMultiOptions(array(
                0 => '- Выберите город -',
                1 => 'Москва',
                2 => 'Санкт-Петербург',
                3 => 'Новосибирск',
            ))
            ->setRequired(false)
            ->addValidator('InArray', false, array('haystack' => array(0, 1, 2, 3)));

        $phone = $this->createElement('phone', 'phone');
        $phone->setLabel('Телефон')
            ->setRequired(false)
            ->addValidator('Phone');

        $comment = $this->createElement('textarea',  'comment');
        $comment->setRequired(false)
            ->addFilter('StringTrim')
            ->addValidator('StringLength', false, array(0, 255));

        $submit = $this->createElement('submit',  'submitButton');
        $submit->setLabel('Отправить');


        $elements = array(
            $firstName,
            $lastName,
            $city,
            $phone,
            $comment,
            $submit,
        );

        $this->setElements($elements);
        parent::setAllDecorators();

        $this->addDisplayGroup(array('firstName', 'lastName', 'city', 'phone'), 'basic', array('legend' => 'Основная информация'));
        $this->addDisplayGroup(array('comment', 'submitButton'), 'additional', array('legend' => 'Другая информация'));

        $this->setDisplayGroupDecorators(array(
            'FormElements',
            'RowDisplayGroup'
        ));
    }
}
